import java.util.*;

public class Row implements Iterator<Double>, Comparator<Row>, Comparable<Row>{

	protected ArrayList<Double> values;
	protected int count;
	protected Matrix matrix;
	
	public Row(int n, Matrix m)
	{
		values = new ArrayList<Double>(n);
		for(int i = 0; i < n; i++)
			values.add(new Double(0));
		count = 0;
		matrix = m;
	}
	
	public void set(int index, double newValue)
	{
		if(index >= values.size())
			throw new NoSuchElementException();
		values.set(index, new Double(newValue));
	}	
	
	public Double get(int index)
	{
		if(index >= values.size())
			throw new NoSuchElementException();
		return values.get(index);
	}
	
	public int size()
	{
		return values.size();
	}

	public boolean hasNext() {
		return count < values.size();
	}

	public Double next() {
		if(count >= values.size())
			throw new NoSuchElementException();
		return values.get(count++);
	}

	public void remove() {
		throw new UnsupportedOperationException();	
		
	}

	public int compare(Row left, Row right) {
		if(left.get(0) > right.get(0))
			return 1;
		else if(left.get(0) == right.get(0))
		{
			Correlation correlation = Correlation.GetInstance();

			return correlation.getOrder(left, right);
		}
		return -1;
	}

	
	public int compareTo(Row right) {
		if(this.get(0) > right.get(0))
			return 1;
		else if(this.get(0) == right.get(0))
		{
			Correlation correlation = Correlation.GetInstance();

			return correlation.getOrder(this, right);
		}		
		return -1;
	}

}
